package com.hnqcgczy.sgzTest.db;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

//alt+insert
public class DBUtils implements DB {
    private String URL = "jdbc:mysql://localhost:3306/dujiaoshou?useSSL=false&serverTimezone=Hongkong&characterEncoding=utf-8&autoReconnect=true";
    private String USERNAME = "root";
    private String PASSWORD = "123456";
    private String DRIVER = "com.mysql.cj.jdbc.Driver";

    public DBUtils() {
        //加载数据库驱动
        try {
            Class.forName(DRIVER);
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        }
    }

    @Override
    public Connection getConn() throws SQLException {
        return DriverManager.getConnection(URL, USERNAME, PASSWORD);
    }

    //用main方法测试
    public static void main(String[] args) {
        DBUtils dbUtils = new DBUtils();
        try {
            Connection conn = dbUtils.getConn();
            System.out.println(conn.isClosed());
        } catch (SQLException throwables) {
            throwables.printStackTrace();
        }

    }
}
